<?php
/**
 * CreateApplication
 */

    echo "file3";
class Application
{
    public function __construct(){
        $param = AcmsBase::loadSystemClass('param');
        define('ROUTE_M',$param->route_m());
        define('ROUTE_C',$param->route_c());
        define('ROUTE_A',$param->route_a());
        $this->init();
    }

    /**
     * event call
     */
    private function init(){
        $controller = $this->loadController();
        if(method_exists($controller,ROUTE_A)){
            if(preg_match('/^[_]/i',ROUTE_A)){
                exit('This action was privated');
            }else{
                call_user_func([$controller,ROUTE_A]);
            }
        }else{
            exit('Gone action');
        }
    }

    /**
     * controller Load
     * @param string $filename
     * @param string $m
     */
    private function loadController($filename = "", $m=""){
        if(empty($filename)){
            $filename = ROUTE_C;
        }
        if(empty($m)){
            $m = ROUTE_M;
        }
        $filepath = PC_PATH.'modules'.DIRECTORY_SEPARATOR.$m.DIRECTORY_SEPARATOR.$filename.'.php';
        if(file_exists($filepath)){
            $classname = $filename;
            include $filepath;
            if($mypath = AcmsBase::myPath($filepath)){
                $classname = 'MY_'.$filename;
                include $mypath;
            }
            if(class_exists($classname)){
                return new $classname;
            }else{
                exit('Gone extent-controller ');
            }
        }else{
            exit('Gone controller');
        }

    }
}